home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / preview.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-10-16  |  39.8 KB  |  1,188 lines

  1. unit Preview;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls, FileCtrl, Menus, Grids, Buttons;
  8.  
  9. type
  10.   TPreviewForm = class(TForm)
  11.     ButtonQuit: TButton;
  12.     LoadTCFile: TButton;
  13.     OpenDrawingFileDialog: TOpenDialog;
  14.     StatusBar: TStatusBar;
  15.     ButtonZoomMinus: TButton;
  16.     CBDisplayDrawingName: TComboBox;
  17.     PaintBox1: TPaintBox;
  18.     HorizontalScrollBar: TScrollBar;
  19.     VerticalScrollBar: TScrollBar;
  20.     Label2: TLabel;
  21.     Label3: TLabel;
  22.     ButtonZoomPlus: TButton;
  23.     ButtonDraw: TButton;
  24.     PopupMenu1: TPopupMenu;
  25.     Circle1: TMenuItem;
  26.     Line1: TMenuItem;
  27.     ButtonNew: TButton;
  28.     ButtonShowProperties: TButton;
  29.     ButtonCircle: TSpeedButton;
  30.     ButtonSpline: TSpeedButton;
  31.     ButtonLine: TSpeedButton;
  32.     ButtonStar: TSpeedButton;
  33.     ButtonPickPoint: TSpeedButton;
  34.     StatusBar1: TStatusBar;
  35.  
  36.     procedure FormCreate(Sender: TObject);
  37.     procedure FormDestroy(Sender: TObject);
  38.     procedure ButtonQuitClick(Sender: TObject);
  39.     procedure PaintBox1Paint(Sender: TObject);
  40.     procedure LoadTCFileClick(Sender: TObject);
  41.     procedure LoadTCFileMouseDown(Sender: TObject; Button: TMouseButton;
  42.       Shift: TShiftState; X, Y: Integer);
  43.     procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  44.       Shift: TShiftState; X, Y: Integer);
  45.     procedure VerticalScrollBarScroll(Sender: TObject;
  46.       ScrollCode: TScrollCode; var ScrollPos: Integer);
  47.     procedure HorizontalScrollBarScroll(Sender: TObject;
  48.       ScrollCode: TScrollCode; var ScrollPos: Integer);
  49.     procedure ButtonZoomPlusClick(Sender: TObject);
  50.     procedure ButtonZoomMinusClick(Sender: TObject);
  51.     procedure ButtonZoomMouseDown(Sender: TObject;
  52.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  53.     procedure ButtonClearClick(Sender: TObject);
  54.     procedure ButtonDrawClick(Sender: TObject);
  55.     procedure ButtonNewClick(Sender: TObject);
  56.     procedure Circle1Click(Sender: TObject);
  57.     procedure Line1Click(Sender: TObject);
  58.     procedure ButtonShowPropertiesClick(Sender: TObject);
  59.     procedure PaintBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  60.       State: TDragState; var Accept: Boolean);
  61.     procedure PaintBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
  62.     procedure ButtonLineClick(Sender: TObject);
  63.     procedure ButtonCircleClick(Sender: TObject);
  64.     procedure ButtonSplineClick(Sender: TObject);
  65.     procedure ButtonStarClick(Sender: TObject);
  66.     procedure ButtonPickPointClick(Sender: TObject);
  67.     procedure PaintBox1StartDrag(Sender: TObject;
  68.       var DragObject: TDragObject);
  69.  
  70.   private
  71.     { Private declarations }
  72.   public
  73.     { Public declarations }
  74.     SDKApp : Variant;  { the overall OLE application object }
  75.     SDKViews: Variant; { the overall SDK  View object }
  76.     TheView: Variant; { the particuler instance of the view }
  77.     SDKDrawings : Variant; { the overall SDK Drawing }
  78.     TheDrawing : Variant; { the particular instance of the drawing }
  79.     Graphics, pIGraphic: Variant; { Graphic variants used for drawing on screen }
  80.     TCFileName : String;
  81.     ViewLeft, ViewTop, ViewWidth, ViewHeight: Double;  { View coordinates }
  82.     ScrollCenterX, ScrollCenterY: Double; { Dead center for scrolling }
  83.     ScrollRangeX, ScrollRangeY: Double; { Scroll range }
  84.     xStart, yStart: Double;  { Coordinates of start point of draw object }
  85.     DragStarted: Boolean;
  86.     SplineStarted: Boolean;
  87.     PointPicked: Boolean;
  88.     SelectedGraphic: Variant;
  89.     procedure LoadTheDrawing(FileName: String);
  90.     procedure ViewSetScrollPos;
  91.     procedure UpdateScrollParams;
  92.     procedure ViewZoomBy(Factor: Double);
  93.     procedure ViewScrollBy(DeltaX: Double; DeltaY: Double);
  94.     procedure PaintBoxRePaint;
  95.     procedure NewDrawing;
  96.   end;
  97.  
  98.  
  99. var
  100.   PreviewForm: TPreviewForm;
  101.  
  102. implementation
  103.  
  104. {$R *.DFM}
  105.  
  106. uses OleAuto, PopUp, Properties;
  107.  
  108. function VarValid(AVar: Variant): Boolean;
  109. begin
  110.     Result := (VarType(AVar) <> varEmpty) and (not VarIsNull(AVar));
  111. end;
  112.  
  113. procedure TPreviewForm.FormCreate(Sender: TObject);
  114. begin
  115.      SDKApp := NULL;
  116.      SDKViews := NULL;
  117.      TheView := NULL;
  118.      SDKDrawings := NULL;
  119.      TheDrawing := NULL;
  120.      SelectedGraphic := NULL;
  121.      { Create the  OLE link to the TC SDK Application }
  122.      SDKApp := CreateOleObject('IMSIGX.Application');
  123.      SDKDrawings := SDKApp.Drawings;  { Get the Drawings Collection to hold our drawings }
  124.      TCFileName := '';
  125.      DragStarted := false;
  126.      SplineStarted := false;
  127.      PointPicked := false;
  128.      NewDrawing;   { set up a new drawing }
  129. end;
  130.  
  131. procedure TPreviewForm.FormDestroy(Sender: TObject);
  132. begin
  133.  
  134.      if VarValid(TheView) then VarClear(TheView);
  135.      if VarValid(SDKViews) then VarClear(SDKViews);
  136.      if VarValid(pIGraphic) then VarClear(pIGraphic);
  137.  
  138.      if VarValid(TheDrawing) then
  139.      begin
  140.          TheDrawing.Close;
  141.          VarClear(TheDrawing);
  142.      end;
  143.  
  144.      if VarValid(SDKDrawings) then VarClear(SDKDrawings);
  145.      if VarValid(SDKApp) then VarClear(SDKApp);
  146. end;
  147.  
  148. procedure TPreviewForm.ButtonQuitClick(Sender: TObject);
  149. begin
  150.    close;
  151. end;
  152.  
  153. procedure TPreviewForm.PaintBox1Paint(Sender: TObject);
  154. begin
  155.      PaintBoxRePaint;
  156. end;
  157.  
  158. procedure TPreviewForm.LoadTCFileClick(Sender: TObject);
  159. var nItem: Integer;
  160. begin
  161.   { Turn off spline }
  162.   SplineStarted := false;
  163.   DragStarted := false;
  164.  
  165.   TCFileName := '';
  166.   { load the drawing from a group of files in a directory }
  167.   { First display Dialog file selection and choose from available files }
  168.   if OpenDrawingFileDialog.Execute then
  169.   begin
  170.  
  171.     TCFileName := OpenDrawingFileDialog.FileName;
  172.     PreviewForm.Caption := OpenDrawingFileDialog.FileName;
  173.     nItem := CBDisplayDrawingName.Items.Add(OpenDrawingFileDialog.FileName);
  174.     CBDisplayDrawingName.ItemIndex := nItem;
  175.     if pos('.tcw', TCFileName) > 2 then
  176.        LoadTheDrawing(TCFileName);
  177.  
  178.     StatusBar.SimpleText := 'Right click on button, object or screen to see the code for the procedure';
  179.   end;
  180. end;
  181.  
  182. { Note: this will be replaced by simple call to TheView.ZoomBy when it is }
  183. { added to the SDK. }
  184. procedure TPreviewForm.ViewZoomBy(Factor: Double);
  185. var
  186.    CanvasDC: HDC;
  187.    VCenterX, VCenterY: Double;
  188.    ViewChanged: Boolean;
  189. begin
  190.     if VarValid(TheDrawing) and VarValid(TheView) then
  191.     begin
  192.         ViewChanged := False;
  193.  
  194.         { Obtain the Device Context for the PaintBox canvas. }
  195.         CanvasDC := PaintBox1.Canvas.Handle;
  196.         TheView.Update := False;  { Delay update until we tell it to. }
  197.         TheView.DC := CanvasDC;
  198.         TheView.MappingMode := MM_TEXT;
  199.         TheView.FixedAspectRatio := TRUE;
  200.  
  201.         { See if we need to start over. }
  202.         if (Factor <= 0.0) or ((ViewWidth = 0) and (ViewHeight = 0)) then
  203.         begin
  204.            { Factor <= 0.0 means reset.  Otherwise, initial settings. }
  205.            TheView.ScreenLeft := 0.0;
  206.            TheView.ScreenTop :=  0.0;
  207.            TheView.ScreenWidth := PaintBox1.Width;
  208.            TheView.ScreenHeight := PaintBox1.Height;
  209.            TheView.ZoomToExtents;
  210.            ViewLeft := TheView.ViewLeft;
  211.            ViewTop := TheView.ViewTop;
  212.            ViewWidth := TheView.ViewWidth;
  213.            ViewHeight := TheView.ViewHeight;
  214.            ViewChanged := True;
  215.         end;
  216.  
  217.         if (Factor > 0.0) and (Factor <> 1.0) then
  218.         begin
  219.            { Keep the center fixed, and change view coordinates. }
  220.            VCenterX := ViewLeft + (ViewWidth/2.0);
  221.            VCenterY := ViewTop - (ViewHeight/2.0);
  222.            ViewWidth := ViewWidth / Factor;
  223.            ViewHeight := ViewHeight / Factor;
  224.            ViewLeft := VCenterX - (ViewWidth/2.0);
  225.            ViewTop := VCenterY + (ViewHeight/2.0);
  226.            ViewChanged := True;
  227.         end;
  228.  
  229.         { Synchronize the view to our new location and zoom. }
  230.         TheView.ViewLeft := ViewLeft;
  231.         TheView.ViewTop := ViewTop;
  232.         TheView.ViewWidth := ViewWidth;
  233.         TheView.ViewHeight := ViewHeight;
  234.  
  235.         { Update display. }
  236.         PaintBoxRePaint;
  237.  
  238.         { Keep scroll bars in sync. }
  239.         if ViewChanged then UpdateScrollParams;
  240.     end;
  241. end;
  242.  
  243. { this loads the drawing from the disk using IMSI SDK }
  244. procedure  TPreviewForm.LoadTheDrawing(FileName: String);
  245. const
  246.   MM_TEXT = 1;
  247. var
  248.     var1, var2: Variant;
  249.     canvasRect: TRect;
  250.     EVar: String;
  251. begin
  252.    if VarValid(SDKApp) and (FileName <> '') then
  253.    begin
  254.        try
  255.        begin
  256.            var1 := null;
  257.            var2 := null;
  258.  
  259.            PaintBox1.Canvas.Brush.Color := clWhite;
  260.            canvasRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Width);
  261.            PaintBox1.Canvas.FillRect(canvasRect);
  262.  
  263.            {  Close any previous open drawings }
  264.            if VarValid(TheView) then
  265.            begin
  266.               VarClear(TheView);
  267.               TheView := NULL;
  268.            end;
  269.  
  270.            if VarValid(SDKViews) then
  271.            begin
  272.               VarClear(SDKViews);
  273.               SDKViews := NULL;
  274.            end;
  275.  
  276.            if VarValid(TheDrawing) then
  277.            begin
  278.                TheDrawing.Close(false);
  279.                VarClear(TheDrawing);
  280.                TheDrawing := NULL;
  281.            end;
  282.  
  283.            { open the graphic TCW file using the SDK method }
  284.            TheDrawing := SDKDrawings.Open(FileName);
  285.            SDKViews := TheDrawing.Views;
  286.            TheView := SDKViews.Add();
  287.  
  288.            { now that we have the particular view for the drawing, call the our
  289.              repaint procedure to handle the painting using the SDK, we set
  290.              the new global coordinates to accomplish the painting }
  291.            { ViewWidth = 0.0 and ViewHeight = 0.0 mean initial settings }
  292.            ViewWidth := 0.0;
  293.            ViewHeight := 0.0;
  294.            ViewLeft := 0.0;
  295.            ViewTop := 0.0;
  296.  
  297.            ViewZoomBy(0.0);   { Specifying 0.0 as the zoom factor redraws... }
  298.        end;
  299.        except
  300.           on E:Exception do
  301.               MessageDlg('Exception Occurred: ' + E.Message, mtInformation, [mbOk], 0);
  302.        end;
  303.    end;
  304. end;
  305.  
  306. procedure TPreviewForm.LoadTCFileMouseDown(Sender: TObject;
  307.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  308. begin
  309.    if Button = mbRight then
  310.    begin
  311.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + (Sender as TButton).Top + (Sender as TButton).Height + 5;
  312.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + (Sender as TButton).Left + X) - (FormPopUp.Width div 2);
  313.        FormPopUp.SetFileName('LoadFile.rtf');
  314.        FormPopUp.show;
  315.    end;
  316.  
  317. end;
  318.  
  319. procedure TPreviewForm.PaintBox1MouseDown(Sender: TObject;
  320.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  321. var vX, vY: Double;
  322.     DispText: String;
  323. begin
  324.    if Button = mbRight then
  325.    begin
  326.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + Y + (Sender as TPaintBox).Top + 5;
  327.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + X) - (FormPopUp.Width div 2);
  328.        FormPopUp.SetFileName('CreateForm.rtf');
  329.        FormPopUp.show;
  330.    end;
  331.    if Button = mbLeft then
  332.    begin
  333.       DispText :=  'X: ' + IntToStr(X) + '   Y: ' + IntToStr(Y);
  334.       if VarValid(TheDrawing) and VarValid(TheView) then
  335.       begin
  336.          TheView.ScreenToView(X, Y, vX, vY);
  337.          DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  338.          DispText := DispText + '   VL: ' + FloatToStr(TheView.ViewLeft);
  339.          if ButtonCircle.Down then
  340.          begin
  341.              Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  342.              xStart := X;
  343.              yStart := Y;
  344.          end
  345.          else if ButtonLine.Down then
  346.          begin
  347.          end;
  348.  
  349.       end;
  350.       StatusBar.SimpleText := DispText;
  351.    end;
  352. end;
  353.  
  354. { Should be called whenever Drawing's bounding box, or Viewport is changed. }
  355. procedure TPreviewForm.UpdateScrollParams;
  356. var
  357.    VarDummy: Variant;
  358.    BBox, BoxMin, BoxMax: Variant;
  359.    X1, Y1, X2, Y2: Double;
  360.    Delta1, Delta2: Double;
  361. begin
  362.     Label2.Visible := True;
  363.     Label3.Visible := True;
  364.  
  365.     HorizontalScrollBar.Visible := True;
  366.     HorizontalScrollBar.Min := 0;
  367.     HorizontalScrollBar.Max := 32000;
  368.     HorizontalScrollBar.LargeChange := 3200;
  369.     HorizontalScrollBar.SmallChange := 320;
  370.  
  371.     VerticalScrollBar.Visible := True;
  372.     VerticalScrollBar.Min := 0;
  373.     VerticalScrollBar.Max := 32000;
  374.     VerticalScrollBar.LargeChange := 3200;
  375.     VerticalScrollBar.SmallChange := 320;
  376.  
  377.     { Arbitrary limits if all else fails. }
  378.     ScrollCenterX := 0.0;
  379.     ScrollCenterY := 0.0;
  380.     ScrollRangeX := 1.0;
  381.     ScrollRangeY := 1.0;
  382.     if VarValid(TheDrawing) then
  383.     begin
  384.          X1 := ViewLeft;
  385.          Y1 := ViewTop - ViewHeight;
  386.          X2 := ViewLeft + ViewWidth;
  387.          Y2 := ViewTop;
  388.          try
  389.              { Set ScrollCenter to center of drawing's graphics. }
  390.              Graphics := TheDrawing.Graphics;
  391.  
  392.              TVarData(varDummy).VType := varError;
  393.              TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  394.              BBox := Graphics.CalcBoundingBox( VarDummy );
  395.  
  396.              if not BBox.Empty then
  397.              begin
  398.                 BoxMin := BBox.Min;
  399.                 BoxMax := BBox.Max;
  400.                 X1 := BoxMin.X;
  401.                 Y1 := BoxMin.Y;
  402.                 X2 := BoxMax.X;
  403.                 Y2 := BoxMax.Y;
  404.                 ScrollCenterX := (X1 + X2)/2.0;
  405.                 ScrollCenterY := (Y1 + Y2)/2.0;
  406.  
  407.                 { Set min and max for range to include current viewport. }
  408.                 if ViewLeft < X1 then X1 := ViewLeft;
  409.                 if (ViewTop - ViewHeight) < Y1 then Y1 := ViewTop - ViewHeight;
  410.                 if (ViewLeft + ViewWidth) > X2 then X2 := ViewLeft + ViewWidth;
  411.                 if ViewTop > Y2 then Y2 := ViewTop;
  412.              end;
  413.          except
  414.          end;
  415.  
  416.          { Set ScrollRange based on largest area included. }
  417.          Delta1 := ScrollCenterX - X1;
  418.          Delta2 := X2 - ScrollCenterX;
  419.          if Delta1 > Delta2 then ScrollRangeX := 2.0 * Delta1
  420.          else ScrollRangeX := 2.0 * Delta2;
  421.  
  422.          Delta1 := ScrollCenterY - Y1;
  423.          Delta2 := Y2 - ScrollCenterY;
  424.          if Delta1 > Delta2 then ScrollRangeY := 2.0 *Delta1
  425.          else ScrollRangeY := 2.0 * Delta2;
  426.     end;
  427.     ViewSetScrollPos;
  428. end;
  429.  
  430. function MyRound(D: Double): Integer;
  431. var
  432.    ConvertString: String;
  433. begin
  434.      ConvertString := FloatToStrF(D, ffFixed, 18, 0);
  435.      Result := StrToInt(ConvertString);
  436. end;
  437.  
  438. procedure TPreviewForm.ViewSetScrollPos;
  439. var
  440.    VCenter: Double;
  441.    IMax: Integer;
  442.    DMax: Double;
  443.    DPos: Double;
  444.    IPos: Integer;
  445. begin
  446.      if ScrollRangeX > 0.0 then
  447.      begin
  448.           IMax := HorizontalScrollBar.Max;
  449.           DMax := IMax;
  450.           VCenter := ViewLeft + (ViewWidth / 2.0);
  451.           DPos := (DMax / 2.0) +
  452.               DMax * (VCenter - ScrollCenterX)/ScrollRangeX;
  453.  
  454.           if DPos <= 0.0 then IPos := 0
  455.           else if DPos >= DMax then IPos := IMax
  456.           else IPos := MyRound(DPos);
  457.           HorizontalScrollBar.Position := IPos;
  458.      end;
  459.  
  460.      if ScrollRangeY > 0.0 then
  461.      begin
  462.           IMax := VerticalScrollBar.Max;
  463.           DMax := IMax;
  464.           VCenter := ViewTop - (ViewHeight / 2.0);
  465.           DPos := (DMax / 2.0) +
  466.               DMax * (VCenter - ScrollCenterY)/ScrollRangeY;
  467.  
  468.           if DPos < 0.0 then IPos := 0
  469.           else if DPos > DMax then IPos := IMax
  470.           else IPos := MyRound(DPos);
  471.           VerticalScrollBar.Position := IPos;
  472.      end;
  473. end;
  474.  
  475. procedure TPreviewForm.ViewScrollBy(DeltaX: Double; DeltaY: Double);
  476. begin
  477.     ViewLeft := ViewLeft + DeltaX;
  478.     ViewTop := ViewTop + DeltaY;
  479.     ViewZoomBy(1.0);
  480. end;
  481.  
  482. procedure TPreviewForm.VerticalScrollBarScroll(Sender: TObject;
  483.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  484. var
  485.    Y, YOrig: Double;
  486.    DPos, DMax: Double;
  487. begin
  488.     if VarValid(TheDrawing) and VarValid(TheView) then
  489.     begin
  490.         Y := ViewTop - (ViewHeight/2.0); { Center point of view. }
  491.         YOrig := Y;
  492.  
  493.         case ScrollCode of
  494.            scLineUp:   Y := Y + (ViewHeight/32.0);  { scroll in the +Y direction }
  495.            scPageUp:   Y := Y + (ViewHeight/8.0);  { scroll in the +Y direction }
  496.            scLineDown: Y := Y - (ViewHeight/32.0);  { scroll in the -Y direction }
  497.            scPageDown: Y := Y - (ViewHeight/8.0);  { scroll in the -Y direction }
  498.            scTrack:
  499.                begin
  500.                     DPos := ScrollPos;
  501.                     DMax := VerticalScrollBar.Max;
  502.                     Y := ScrollCenterY -
  503.                       (DPos / DMax - 0.5) * ScrollRangeY;
  504.                end
  505.            else Exit;
  506.         end;
  507.  
  508.         ViewScrollBy(0.0, Y - YOrig);
  509.     end;
  510. end;
  511.  
  512. procedure TPreviewForm.HorizontalScrollBarScroll(Sender: TObject;
  513.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  514. var
  515.    X, XOrig: Double;
  516.    DPos, DMax: Double;
  517. begin
  518.     if VarValid(TheDrawing) and VarValid(TheView) then
  519.     begin
  520.         X := ViewLeft + (ViewWidth/2.0); { Center point of view. }
  521.         XOrig := X;
  522.  
  523.         case ScrollCode of
  524.            scLineUp:   X := X - (ViewWidth/32.0);  { scroll in the -X direction }
  525.            scPageUp:   X := X - (ViewWidth/8.0);  { scroll in the -X direction }
  526.            scLineDown: X := X + (ViewWidth/32.0);  { scroll in the +X direction }
  527.            scPageDown: X := X + (ViewWidth/8.0);  { scroll in the +X direction }
  528.            scTrack:
  529.                begin
  530.                     DPos := ScrollPos;
  531.                     DMax := HorizontalScrollBar.Max;
  532.                     X := ScrollCenterX +
  533.                       (DPos / DMax - 0.5) * ScrollRangeX;
  534.                end
  535.            else Exit;
  536.         end;
  537.  
  538.         ViewScrollBy(X - XOrig, 0.0);
  539.     end;
  540. end;
  541.  
  542. procedure TPreviewForm.ButtonZoomPlusClick(Sender: TObject);
  543. begin
  544.     { Turn off spline }
  545.     SplineStarted := false;
  546.     DragStarted := false;
  547.     
  548.     ViewZoomBy(1.414);
  549. end;
  550.  
  551. procedure TPreviewForm.ButtonZoomMinusClick(Sender: TObject);
  552. begin
  553.     { Turn off spline }
  554.     SplineStarted := false;
  555.     DragStarted := false;
  556.     
  557.     ViewZoomBy(0.707);
  558. end;
  559.  
  560. procedure TPreviewForm.ButtonZoomMouseDown(Sender: TObject;
  561.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  562. begin
  563.    if Button = mbRight then
  564.    begin
  565.        FormPopUp.Top := PreviewForm.ClientOrigin.Y + (Sender as TButton).Top + (Sender as TButton).Height + 5;
  566.        FormPopUp.Left := (PreviewForm.ClientOrigin.X + (Sender as TButton).Left + X) - (FormPopUp.Width div 2);
  567.        FormPopUp.SetFileName('zoom.rtf');
  568.        FormPopUp.show;
  569.    end;
  570. end;
  571.  
  572. { This procedure repaints the screen with the current picture }
  573. procedure TPreviewForm.PaintBoxRePaint;
  574. const
  575.   MM_TEXT = 1;
  576. var CanvasDC: HDC;
  577.     canvasRect: TRect;
  578.     ViewChanged: Boolean;
  579. begin
  580.     { clear the screen to white first }
  581.     canvasRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
  582.     PaintBox1.Canvas.Brush.Color := clWhite;
  583.     PaintBox1.Canvas.FillRect(canvasRect);
  584.     if VarValid(TheDrawing) and VarValid(TheView) then
  585.     begin
  586.         { obtain the Device Context for the paintBox canvas }
  587.         CanvasDC := PaintBox1.Canvas.Handle;
  588.  
  589.         TheView.Update := FALSE;  { delay update until we tell it to }
  590.         TheView.DC := CanvasDC;
  591.         TheView.MappingMode := MM_TEXT;
  592.         TheView.FixedAspectRatio := TRUE;
  593.  
  594.         ViewChanged := (ViewWidth = 0) and (ViewHeight = 0);
  595.         if ViewChanged then
  596.         begin
  597.            { Initial settings }
  598.            TheView.ScreenLeft := canvasRect.Left;
  599.            TheView.ScreenTop :=  canvasRect.Top;
  600.            TheView.ScreenWidth := canvasRect.Right - canvasRect.Left;
  601.            TheView.ScreenHeight := canvasRect.Bottom - canvasRect.Top;
  602.            TheView.ZoomToExtents;
  603.         end
  604.         else
  605.         begin
  606.            { Saved settings }
  607.            TheView.Refresh;
  608.         end;
  609.         ViewLeft := TheView.ViewLeft;
  610.         ViewTop := TheView.ViewTop;
  611.         ViewWidth := TheView.ViewWidth;
  612.         ViewHeight := TheView.ViewHeight;
  613.  
  614.         if ViewChanged then UpdateScrollParams;
  615.     end;
  616. end;
  617.  
  618. procedure TPreviewForm.ButtonClearClick(Sender: TObject);
  619. begin
  620.   { clear the screen of the any drawing }
  621.   PaintBox1.Canvas.Brush.Color := clWhite;
  622.   PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  623.  
  624.   { remove any Variant association and close the drawing }
  625.   if VarValid(TheView) then
  626.   begin
  627.      VarClear(TheView);
  628.      TheView := NULL;
  629.   end;
  630.  
  631.   if VarValid(SDKViews) then
  632.   begin
  633.      VarClear(SDKViews);
  634.      SDKViews := NULL;
  635.   end;
  636.  
  637.   if VarValid(TheDrawing) then
  638.   begin
  639.       TheDrawing.Close(false);
  640.       VarClear(TheDrawing);
  641.       TheDrawing := NULL;
  642.   end;
  643.   UpdateScrollParams;
  644. end;
  645.  
  646. procedure TPreviewForm.ButtonDrawClick(Sender: TObject);
  647. begin
  648.   { Turn off spline }
  649.   SplineStarted := false;
  650.   DragStarted := false;
  651.  
  652.   PopupMenu1.AutoPopup := False;
  653.   PopupMenu1.Popup(PreviewForm.ClientOrigin.X + ButtonDraw.Left, PreviewForm.ClientOrigin.Y + ButtonDraw.Top + ButtonDraw.Height);
  654. end;
  655.  
  656. procedure TPreviewForm.ButtonNewClick(Sender: TObject);
  657. begin
  658.    { Turn off spline }
  659.    SplineStarted := false;
  660.    DragStarted := false;
  661.  
  662.    if VarValid(SDKApp) then
  663.    begin
  664.       NewDrawing;   { set up a new drawing }
  665.    end;
  666.  
  667. end;
  668.  
  669. procedure TPreviewForm.Circle1Click(Sender: TObject);
  670. var
  671.     xc, yc, zc, xp, yp, zp: double;
  672.     vh, vw, vl, vt, vx, vy: double;
  673.     vLeft, vTop: double;
  674. begin
  675.  
  676.     { turn off spline and drag }
  677.     SplineStarted := false;
  678.     DragStarted := false;
  679.  
  680.     { Circle from center }
  681.     { make sure that a drawing is ready for use }
  682.     if VarValid(TheView) and VarValid(TheDrawing) then
  683.     begin
  684.  
  685.         PaintBox1.Canvas.Brush.Color := clWhite;
  686.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  687.  
  688.         xc := (TheView.ViewLeft + TheView.ViewWidth) / 2.0;
  689.         yc := (TheView.ViewTop - TheView.ViewHeight) / 2.0;
  690.         zc := 0.0;
  691.         xp := TheView.ViewLeft;
  692.         yp := TheView.ViewTop;
  693.         zp := 0.0;
  694.  
  695.         Graphics := TheDrawing.Graphics;
  696.         pIGraphic := Graphics.AddCircleCenterAndPoint(xc, yc, zc, xp, yp, zp);
  697.  
  698.         PaintBoxRePaint;
  699.         UpdateScrollParams;
  700.     end;
  701. end;
  702.  
  703. procedure TPreviewForm.Line1Click(Sender: TObject);
  704.     { draw a line on screen }
  705. var
  706.     xc, yc, zc, xp, yp, zp: double;
  707.     vh, vw, vl, vt: double;
  708. begin
  709.     { turn off spline and drag }
  710.     SplineStarted := false;
  711.     DragStarted := false;
  712.  
  713.    { Line from two points }
  714.     { make sure that a drawing is ready for use }
  715.     if VarValid(TheView) and VarValid(TheDrawing) then
  716.     begin
  717.         { clear screen first }
  718.         PaintBox1.Canvas.Brush.Color := clWhite;
  719.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  720.  
  721.         { we need to draw in view coordinates not screen coordinates as the drawing
  722.           by default is in inches. Remember that the default is: inches with the screen
  723.           center as 0.0, 0.0}
  724.         xc := (TheView.ViewWidth) / 2.0;;
  725.         yc := 0.0;
  726.         zc := 0.0;
  727.         xp := (TheView.ViewLeft) + (TheView.ViewWidth / 2.0);
  728.         yp := 0.0;
  729.         zp := 0.0;
  730.  
  731.         xc := (TheView.ViewLeft + TheView.ViewWidth) / 2.0;
  732.         yc := (TheView.ViewTop - TheView.ViewHeight) / 2.0;
  733.         zc := 0.0;
  734.         xp := TheView.ViewLeft;
  735.         yp := TheView.ViewTop;
  736.  
  737.         Graphics := TheDrawing.Graphics;
  738.         pIGraphic := Graphics.AddLineSingle(xc, yc, zc, xp, yp, zp);
  739.  
  740.         PaintBoxRePaint;
  741.         UpdateScrollParams;
  742.     end;
  743. end;
  744.  
  745. procedure TPreviewForm.ButtonShowPropertiesClick(Sender: TObject);
  746. var pItem, pProps, ValueStr: Variant;
  747.     pTypeName, pName, TypeStr: String;
  748.     pType: Integer;
  749.     pValue: Variant;
  750.     Count, ii, TotalWidth: Integer;
  751.     isArray: Boolean;
  752.     Col0, Col1, Col2: Integer;
  753. begin
  754.    if VarValid(SDKApp) then
  755.    begin
  756.        pProps := NULL;
  757.        pProps := TheDrawing.Properties;
  758.        Count := pProps.Count;
  759.        Col0 := 0; Col1 := 0; Col2 := 0; TotalWidth := 0;
  760.        with FormProperties.StringGridProperties do
  761.        begin
  762.           Cells[0, 0] := 'Property';
  763.           if Canvas.TextWidth('Property') > Col0 then Col0 := Canvas.TextWidth('Property');
  764.           Cells[1, 0] := 'Type';
  765.           if Canvas.TextWidth('Type') > Col1 then Col1 := Canvas.TextWidth('Type');
  766.           Cells[2, 0] := 'Value';
  767.           if Canvas.TextWidth('Value') > Col2 then Col2 := Canvas.TextWidth('Value');
  768.           RowCount := 1;
  769.  
  770.           for ii:=0 to Count-1 do
  771.           begin
  772.               { This is the way to access a property which takes a parameter }
  773.               { Item(Parameter) must be used as an array Item[parameter] }
  774.               pItem := pProps.Item[ii];
  775.               RowCount := RowCount + 1;
  776.               { get the name of the property }
  777.               pName := pItem.Name;
  778.  
  779.               { find max width to set col, This uses the Canvas method TextWidth to
  780.                 find the string width in pixels }
  781.               if Canvas.TextWidth(pName) > Col0 then Col0 := Canvas.TextWidth(pName);
  782.  
  783.               Cells[0, ii+1] := pName;
  784.               { we need a try - exception here because the return may throw an exception on 'no value' }
  785.               try
  786.                  pType := pItem.Type;
  787.                  isArray := False;
  788.                  if (pType and varArray) <> 0 then
  789.                  begin
  790.                       isArray := True;
  791.                       pType := pType and (not varArray);
  792.                  end;
  793.  
  794.                  { we need to define what the TYPE means in english }
  795.                  case pType of
  796.                       varEmpty: { VT_EMPTY } pTypeName := 'Empty';
  797.                       varSmallint: { VT_I2 } pTypeName := 'Integer';
  798.                       varInteger: { VT_I4 } pTypeName := 'Long';
  799.                       varSingle: { VT_R4 } pTypeName := 'Real';
  800.                       varDouble: { VT_R8 } pTypeName := 'Double';
  801.                       varOleStr: { VT_BSTR } pTypeName := 'String';
  802.                       varBoolean: { VT_BOOL } pTypeName := 'Boolean';
  803.                       varByte: { VT_UI1 } pTypeName := 'Byte';
  804.                       else pTypeName := 'Unknown (' + IntToStr(pType) + ')';
  805.                   end;
  806.  
  807.                   { if an array type then add extra wording }
  808.                   if isArray then
  809.                   begin
  810.                      TypeStr := 'Array of ' + pTypeName;
  811.                      Cells[1, ii+1] := TypeStr;
  812.                      if Canvas.TextWidth(TypeStr) > Col1 then Col1 := Canvas.TextWidth(TypeStr);
  813.                   end
  814.                   else
  815.                   begin
  816.                      Cells[1, ii+1] := pTypeName;
  817.                      if Canvas.TextWidth(pTypeName) > Col1 then Col1 := Canvas.TextWidth(pTypeName);
  818.                   end;
  819.  
  820.               except
  821.                   Cells[1, ii+1] := 'Error';
  822.               end;
  823.  
  824.               try
  825.                   PValue := pItem.Value;
  826.                   if VarType(PValue) in [varSmallint, varInteger, varSingle, varDouble, varOleStr, varBoolean, varByte] then
  827.                      VarCast (ValueStr, pValue, varString)   { convert to string }
  828.                   else
  829.                      ValueStr := 'Unknown';
  830.  
  831.                   Cells[2, ii+1] := ValueStr;
  832.                   if Canvas.TextWidth(ValueStr) > Col2 then Col2 := Canvas.TextWidth(ValueStr);
  833.               except
  834.                   if Canvas.TextWidth('Error') > Col2 then Col2 := Canvas.TextWidth('Error');
  835.                   Cells[2, ii+1] := 'Error';
  836.               end;
  837.  
  838.           end;
  839.  
  840.  
  841.           ColWidths[0] := Col0 + 5;
  842.           ColWidths[1] := Col1 + 5;
  843.           ColWidths[2] := Col2 + 5;
  844.           TotalWidth := Col0 + Col1 + Col2 + 15;
  845.           Width := TotalWidth + 25;
  846.           FormProperties.Width := Width + 10;
  847.           FixedRows := 1;
  848.        end;
  849.  
  850.        FormProperties.show;
  851.        VarClear(pProps);
  852.        VarClear(pItem);
  853.    end;
  854. end;
  855.  
  856. procedure TPreviewForm.PaintBox1DragOver(Sender, Source: TObject; X,
  857.   Y: Integer; State: TDragState; var Accept: Boolean);
  858. var vX, vY: Double;
  859.     DispText: String;
  860.     TheStar: Variant;
  861. begin
  862.     DispText :=  'X: ' + IntToStr(X) + '   Y: ' + IntToStr(Y);
  863.     if VarValid(TheView) then
  864.     begin
  865.        if not DragStarted then
  866.        begin
  867.           if (ButtonCircle.Down) or (ButtonLine.Down) or (ButtonStar.Down) or (ButtonPickPoint.Down) then
  868.           begin
  869.  
  870.               { This starts the drawing fixing the first point as xStart and yStart }
  871.               { first get the view coordinates from the screen coordinates of the
  872.                 mouse click }
  873.               TheView.ScreenToView(X, Y, vX, vY);
  874.               Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  875.               xStart := vX;
  876.               yStart := vY;
  877.               DragStarted := true;
  878.  
  879.               if ButtonPickPoint.Down then
  880.                   PointPicked := true;
  881.               { display in status box }
  882.               DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  883.               varClear(pIGraphic);
  884.           end
  885.           else if ButtonSpline.Down then
  886.           begin
  887.               if not SplineStarted then
  888.               begin
  889.                   TheView.ScreenToView(X, Y, vX, vY);
  890.                   Graphics := TheDrawing.Graphics;  { get the graphic to start drawing }
  891.                   xStart := vX;
  892.                   yStart := vY;
  893.                   DragStarted := true;
  894.  
  895.                   { display in status box }
  896.                   DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  897.               end;
  898.           end
  899.           else
  900.           begin
  901.               { no draw button down, so just display coordinates }
  902.               TheView.ScreenToView(X, Y, vX, vY);
  903.               DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  904.           end;
  905.        end
  906.        else { still dragging the mouse }
  907.        begin
  908.  
  909.           { if we wish to rubber bank the drawing object we have to erase the
  910.             previous object and draw the temporary object from new positions }
  911.  
  912.           { just display the coordinates to the StatusBox }
  913.           TheView.ScreenToView(X, Y, vX, vY);
  914.           DispText := DispText + '   View -> X: ' + FloatToStr(vX) + '   Y: ' + FloatToStr(vY);
  915.        end;
  916.     end;
  917.     { display coordinates of mouse to Status Box }
  918.     StatusBar.SimpleText := DispText;
  919. end;
  920.  
  921. procedure TPreviewForm.PaintBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
  922. var  vX, vY: double;
  923.      pickCount, ii: Integer;
  924.      varX, varY, varZ: Double;
  925.      varDummy, ThePickedResults: Variant;
  926.      pIVertex, IVertices: Variant;
  927.      TheItem, PickGraphic, ThePenColor, pProp: Variant;
  928.  
  929. begin
  930.  
  931.     if (DragStarted = true) and VarValid(TheView) and
  932.        ((ButtonCircle.Down = true) or (ButtonLine.Down = true) or (ButtonSpline.Down = true) or
  933.         (ButtonStar.Down = true) or (ButtonPickPoint.Down = true)) then
  934.     begin
  935.  
  936.         { the user has now released the mouse button and we must draw the object with
  937.           the coordinates from this mouse point }
  938.  
  939.         { clear the screen first. This would not be necessary if the drawing scale wasn't changing }
  940.         PaintBox1.Canvas.Brush.Color := clWhite;
  941.         PaintBox1.Canvas.FillRect(Rect(0, 0, PaintBox1.Width, PaintBox1.Height));
  942.  
  943.         { get the view coordinates for the screen mouse position }
  944.         TheView.ScreenToView(X, Y, vX, vY);
  945.  
  946.         { with the start and ending coordinates we use the IMSI SDK to draw the circle line or slpine }
  947.         if ButtonCircle.Down = true then { draw circle center and radius point }
  948.             pIGraphic := Graphics.AddCircleCenterAndPoint(xStart, yStart, 0, vX, vY, 0)
  949.         else if ButtonLine.Down = true then  { drawing line start and end point }
  950.             pIGraphic := Graphics.AddLineSingle(xStart, yStart, 0, vX, vY, 0)
  951.         else if ButtonSpline.Down = true then { draw spline, start point and subsequent mouse drag points }
  952.         begin
  953.             { First two points on spline come from draw Over and here from End drag }
  954.             if not SplineStarted then { first time through with spline }
  955.             begin
  956.                 varX := xStart;
  957.                 varY := yStart;
  958.                 varZ := 0.0;
  959.                 pIGraphic := Graphics.AddCurveSpline(varX, varY, 0.0);
  960.                 SplineStarted := true;  { mark as starting spline for subsequent mouse clicks and drags }
  961.  
  962.                 TVarData(varDummy).VType := varError;
  963.                 TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  964.  
  965.                 IVertices := NULL;
  966.              IVertices := pIGraphic.Vertices;
  967.                 varX := vX;
  968.                 varY := vY;
  969.                 varZ := 0.0;
  970.                 pIVertex := NULL;
  971.                 {pIvertex := IVertices.Add(varX, varY, varZ, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy);}
  972.                 pIvertex := IVertices.Add(varX, varY, varZ,,,,,,,,); { add a vertex. Delphi allows commas as place holder }
  973.  
  974.                 if VarValid(pIVertex) then
  975.                     VarClear(pIVertex);
  976.  
  977.                 if VarValid(IVertices) then
  978.                     VarClear(IVertices);
  979.  
  980.             end
  981.             else
  982.             begin
  983.                 TVarData(varDummy).VType := varError;
  984.                 TVarData(varDummy).VError := DISP_E_PARAMNOTFOUND;
  985.  
  986.                 IVertices := NULL;
  987.              IVertices := pIGraphic.Vertices;
  988.                 varX := vX;
  989.                 varY := vY;
  990.                 varZ := 0.0;
  991.                 pIVertex := NULL;
  992.                 {pIvertex := IVertices.Add(varX, varY, varZ, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy, varDummy);}
  993.                 pIvertex := IVertices.Add(varX, varY, varZ,,,,,,,,);
  994.  
  995.                 if VarValid(pIVertex) then
  996.                     VarClear(pIVertex);
  997.  
  998.                 if VarValid(IVertices) then
  999.                     VarClear(IVertices);
  1000.             end;
  1001.         end
  1002.         else if ButtonStar.Down = true then  { drawing Point, star, box or what ever }
  1003.         begin
  1004. { !!!!!!!!!!!!!!!!!!!! FAILS AT DBAPI/DBD.cpp Line 2108 !!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  1005.             pIGraphic := Graphics.AddStar(xStart, yStart, 0.0);
  1006.         end
  1007.         else if (ButtonPickPoint.Down = true) and (PointPicked = true) then  { Pick point see if on graphic and highlite }
  1008.         begin
  1009.             try
  1010.                 StatusBar1.SimpleText := 'Count: ';
  1011.                 ThePickedResults := null;
  1012.                 ThePickedResults := TheView.PickPoint(xStart, yStart,0.1,,,,,,);
  1013.  
  1014.                 pickCount := ThePickedResults.Count;
  1015.                 if pickCount > 0 then
  1016.                 begin
  1017.                     { First deselect the current selected graphic if any }
  1018.                     if VarValid(SelectedGraphic) then
  1019.                     begin
  1020.                         PickGraphic := SelectedGraphic;
  1021.                         pProp := NULL;
  1022.                         pProp := PickGraphic.Properties;
  1023.  
  1024.                         ThePenColor := NULL;
  1025.                         ThePenColor := pProp.Item['PenColor'];
  1026.                         ThePenColor.Value :=  $000000;
  1027.                         VarClear(SelectedGraphic);
  1028.                         SelectedGraphic := NULL;
  1029.                     end;
  1030.  
  1031.                     for ii := 0 to pickCount - 1 do
  1032.                     begin
  1033.                         TheItem := ThePickedResults.Item[ii];  { must pass the parameter as if an array }
  1034.                         PickGraphic := TheItem.Graphic;
  1035.                         pProp := NULL;
  1036.                         pProp := PickGraphic.Properties;
  1037.  
  1038.                         ThePenColor := NULL;
  1039.                         ThePenColor := pProp.Item['PenColor'];
  1040.                         ThePenColor.Value :=  $0000FF;
  1041.  
  1042.                         SelectedGraphic := PickGraphic;
  1043.  
  1044.                         VarClear(TheItem);
  1045.                         VarClear(PickGraphic);
  1046.                         VarClear(ThePenColor);
  1047.                         VarClear(pProp);
  1048.  
  1049.                     end;
  1050.                     StatusBar1.SimpleText := 'Count: ' + IntToStr(pickCount);
  1051.                 end;
  1052.  
  1053.  
  1054.  
  1055.                 VarClear (ThePickedResults);
  1056.                 PointPicked := false;
  1057.             except
  1058.                on E:Exception do
  1059.                begin
  1060.                    StatusBar1.SimpleText := 'Count: 0';
  1061.                    if VarValid(ThePickedResults) then
  1062.                        VarClear(ThePickedResults);
  1063.  
  1064.                    { do nothing as not graphic found at point }
  1065.                end;
  1066.             end;
  1067.         end;
  1068.  
  1069.         PaintBoxRePaint;
  1070.         UpdateScrollParams;
  1071.  
  1072.         { clear the graphics variant }
  1073.         if not SplineStarted then
  1074.         begin
  1075.            varClear(pIGraphic);
  1076.            DragStarted := false;
  1077.         end;
  1078.     end;
  1079. end;
  1080.  
  1081. procedure TPreviewForm.ButtonLineClick(Sender: TObject);
  1082. begin
  1083.    { draws a line from mouse down to mouse up }
  1084.     SplineStarted := false;
  1085.     DragStarted := false;
  1086.  
  1087. end;
  1088.  
  1089. procedure TPreviewForm.ButtonCircleClick(Sender: TObject);
  1090. begin
  1091.     StatusBar.SimpleText := 'Click and drag with mouse to draw circle';
  1092.     SplineStarted := false;
  1093.     DragStarted := false;
  1094. end;
  1095.  
  1096. procedure TPreviewForm.ButtonSplineClick(Sender: TObject);
  1097. begin
  1098.     SplineStarted := false;
  1099.     DragStarted := false;
  1100. end;
  1101.  
  1102. procedure TPreviewForm.ButtonStarClick(Sender: TObject);
  1103. begin
  1104.    { draw a Start. Could be any point object: point, circle, star, dot, square }
  1105.     SplineStarted := false;
  1106.     DragStarted := false;
  1107. end;
  1108.  
  1109. procedure TPreviewForm.ButtonPickPointClick(Sender: TObject);
  1110. begin
  1111.     { stop the spline if it is still waiting for points }
  1112.     SplineStarted := false;
  1113.     DragStarted := false;
  1114.     PointPicked := false; { start the picking by setting to false to clear any previous click }
  1115. end;
  1116.  
  1117. procedure TPreviewForm.NewDrawing;
  1118. const
  1119.   MM_TEXT = 1;
  1120. var
  1121.     var1, var2: Variant;
  1122.     canvasRect: TRect;
  1123.     EVar, DispText: String;
  1124. begin
  1125.     if VarValid(SDKApp) then
  1126.     begin
  1127.         try
  1128.         begin
  1129.             var1 := null;
  1130.             var2 := null;
  1131.  
  1132.             {  Close any previous open drawings }
  1133.             if VarValid(TheView) then
  1134.             begin
  1135.                VarClear(TheView);
  1136.                TheView := NULL;
  1137.             end;
  1138.  
  1139.             if VarValid(SDKViews) then
  1140.             begin
  1141.                VarClear(SDKViews);
  1142.                SDKViews := NULL;
  1143.             end;
  1144.  
  1145.             if VarValid(TheDrawing) then
  1146.             begin
  1147.                 TheDrawing.Close(false);
  1148.                 VarClear(TheDrawing);
  1149.                 TheDrawing := NULL;
  1150.             end;
  1151.  
  1152.             { Get a new drawing using the SDK method }
  1153.             TheDrawing := SDKDrawings.Add;
  1154.             SDKViews := TheDrawing.Views;
  1155.             TheView := SDKViews.Add();
  1156.  
  1157.             { now that we have the particular view for the drawing, call the our
  1158.               repaint procedure to handle the painting using the SDK, we set
  1159.               the new global coordinates to accomplish the painting}
  1160.             ViewWidth := 0.0;{PaintBox1.Width;}
  1161.             ViewHeight := 0.0;{PaintBox1.Height; }
  1162.             ViewLeft := 0.0;
  1163.             ViewTop := 0.0;
  1164.  
  1165.             PaintBoxRePaint; { call the repaint procedure }
  1166.             UpdateScrollParams;
  1167.  
  1168.             DispText := 'VL: ' + FloatToStr(TheView.ViewLeft) +
  1169.              '  VT: ' + FloatToStr(TheView.ViewTop) + '  VW: ' + FloatToStr(TheView.ViewWidth) +
  1170.              '  VH: ' + FloatToStr(TheView.ViewHeight);
  1171.  
  1172.             StatusBar1.SimpleText := DispText;
  1173.         end;
  1174.         except
  1175.            on E:Exception do
  1176.                MessageDlg('Exception Occurred: ' + E.Message, mtInformation, [mbOk], 0);
  1177.         end;
  1178.     end;
  1179. end;
  1180.  
  1181. procedure TPreviewForm.PaintBox1StartDrag(Sender: TObject;
  1182.   var DragObject: TDragObject);
  1183. begin
  1184.     { unfortunately DragStart does not pass mouse coordinates so must use DragOver }
  1185. end;
  1186.  
  1187. end.
  1188.